package top.goldenyear.porpoise.system.setting.controller.admin;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.system.setting.dto.DictSearchReq;
import top.goldenyear.porpoise.system.setting.model.Dict;
import top.goldenyear.porpoise.system.setting.service.DictService;

/**
 * 字典表 Controller 控制层
 *
 * @author airhead
 * @since 2024-10-15
 */
@Component(tag = "adminApi")
@Mapping("/setting/dict")
@Slf4j
public class DictAdminController extends BaseController {
  @Inject private DictService service;

  @Post
  @Mapping("create")
  public Ret create(@Body Dict dict) {
    return Ret.okWithData(service.createDict(dict));
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Body Dict dict) {
    return Ret.okWithData(service.updateDict(dict));
  }

  @Get
  @Mapping("get")
  public Ret get(@Param Integer id) {
    return Ret.okWithData(service.getDict(id));
  }

  @Post
  @Delete
  @Mapping("delete")
  public Ret delete(@Param Integer id) {
    return Ret.okWithData(service.deleteDict(id));
  }

  @Post
  @Delete
  @Mapping("batchDel")
  public Ret batchDel(@Body List<Integer> ids) {
    return Ret.okWithData(service.batchDelDict(ids));
  }

  @Get
  @Mapping("paginate")
  public Ret paginate(QPage qPage, DictSearchReq searchReq) {
    return Ret.okWithData(service.paginateDict(qPage, searchReq));
  }

  @Get
  @Mapping("list")
  public Ret list() {
    Dict dict = getBean(Dict.class);
    return Ret.okWithData(service.listDict(dict));
  }

  @Get
  @Mapping("simpleList")
  public Ret simpleList() {
    Dict dict = getBean(Dict.class);
    return Ret.okWithData(service.simpleListDict(dict));
  }
}
